package com.demo.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.demo.api.model.User;
import com.demo.api.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/")
@Api(value = "TestController|一个用来测试swagger注解的控制器")
public class TestController {

	@Reference(version = "1.0.0")
	private UserService testService;

	@GetMapping("hello")
	public String hello() {
		return testService.sayHello("Hello springboot and dubbo!");
	}

	@GetMapping("user")
	public User user() {
		return testService.findUser();
	}

	@GetMapping("list")
	public List<User> list(@RequestParam(defaultValue = "1") int page,
			@RequestParam(defaultValue = "10") int pageSize) {
		return testService.getUser(page, pageSize);
	}

	@RequestMapping(value = "add", method = RequestMethod.POST)
	public List<User> add(@RequestBody User user) {
		System.out.println(user.toString());
		return null;
	}



	/*注意：@ApiImplicitParam的参数说明：
	paramType：指定参数放在哪个地方
	{
	header：请求参数放置于Request Header，使用@RequestHeader获取
	query：请求参数放置于请求地址，使用@RequestParam获取
	path：（用于restful接口）-->请求参数的获取：@PathVariable
	body：（不常用）
	form（不常用）
	}

	name：参数名
	dataType：参数类型
	required：参数是否必须传 true | false
	value：说明参数的意思
	defaultValue：参数的默认值*/
	// 从redis获取某个用户
	@ApiOperation(value="根据用户编号获取用户信息", notes="填1008测试")
	@ApiImplicitParam(paramType="query", name = "key", value = "用户编号", required = true, dataType = "String")
	@RequestMapping(value = "/getuserfromredis", method = RequestMethod.GET)
	public User getRedis(@RequestParam String key) {
		return testService.getUserForRedis(key);
	}
}
